

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>设置我的密码</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <script src="../../layuilay/layui.js" charset="utf-8"></script>
  <script src="../../js/jquery-3.4.1.min.js" charset="utf-8"></script>
  <link rel="stylesheet" href="../../layuilay/css/layui.css"  media="all">
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">修改密码</div>
          <div class="layui-card-body" pad15>
            
            <div class="layui-form" lay-filter="">
              <div class="layui-form-item">
                <label class="layui-form-label">当前密码</label>
                <div class="layui-input-inline">
                  <input id='pwds' type="password"  onblur="oldpassword()" name=""  lay-verType="tips" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline">
                  <input type="password" id="newpwd"  lay-verify="pass"    class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">确认新密码</label>
                <div class="layui-input-inline">
                  <input type="password" id="newpassword" onblur="newpass()"  class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn"  onclick="updatepwd()">确认修改</button>
                </div>
              </div>
            </div>
            
          </div>
        </div>
      </div>
    </div>
  </div>
    
  <script type="text/javascript">
  layui.use(['jquery','layer'], function(){
	     var $ = layui.$;
	     var layer = layui.layer;
  })
  function oldpassword(){
	  var pwd = window.localStorage.getItem("loginpassword");
	  var pwds = $("#pwds").val()
	  if(pwd!=pwds){
		  layer.msg("当前密码输入错误!");
		  $("#pwds").val("");
	  }
  }

  function newpass(){
	  var pwds = $("#pwds").val()
	  var newpwd = $("#newpwd").val()
	  var newpassword = $("#newpassword").val()
	  if(newpwd==""||newpassword==""){
		  layer.msg("密码框不能为空");
	  }else if(newpwd!=newpassword){
		  layer.msg("两次输入的密码不一致");
		  $("#newpwd").val("");
		  $("#newpassword").val("");
	  }else if(newpwd==pwds){
          layer.msg("新密码 不能和旧密码一致!");
          $("#newpwd").val("");
          $("#newpassword").val("");
      }else if(pwds==newpwd){
		  layer.msg("新密码 不能和旧密码一致!");
		  $("#pwds").val("");
		  $("#newpwd").val("");
          $("#newpassword").val("");
	  }
  }
  function updatepwd(){
	  var pwds = $("#pwds").val()
      var newpwd = $("#newpwd").val()
      var newpassword = $("#newpassword").val()
	  var studentid = window.localStorage.getItem("loginid");
	  var newpassword = $("#newpassword").val()
	  if (pwds == ""){
          layer.msg("请输入当前密码");
          flag = false;
          return false;
      }else if ("" == newpwd){
          layer.msg("请输入新的密码！");
          flag = false;
          return false;
      }else if ("" == newpassword){
          layer.msg("请确认新的密码！");
          flag = false;
          return false;
      }
	  if(flag == true){
          return true;
      }
     var flag=$.ajax({
              url:"../../updatePwd?pwd="+newpassword+"&id="+studentid,
              data:{},
              dataType:"json",
              type:"post",
              success:function(res){
                  if(res.success){
                	  alert("修改成功");
                	  window.localStorage.clear();
                     window.location.href="../user/login.html";
                     window.history.back(-1);
                  }else{
                	  alert("修改失败");
                  }
              }
          })
  }

  
  </script>
</body>
</html>